﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.LSIS
{
	/// <summary>
	/// XGK Fast Enet I/F module supports open Ethernet. It provides network configuration that is to connect LSIS and other company PLC, PC on network
	/// </summary>
	/// <remarks>
	/// Address example likes the follow
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>示例</term>
	///     <term>地址进制</term>
	///     <term>字操作</term>
	///     <term>位操作</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>*</term>
	///     <term>P</term>
	///     <term>PX100,PB100,PW100,PD100,PL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>*</term>
	///     <term>M</term>
	///     <term>MX100,MB100,MW100,MD100,ML100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>*</term>
	///     <term>L</term>
	///     <term>LX100,LB100,LW100,LD100,LL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>*</term>
	///     <term>K</term>
	///     <term>KX100,KB100,KW100,KD100,KL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>*</term>
	///     <term>F</term>
	///     <term>FX100,FB100,FW100,FD100,FL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>T</term>
	///     <term>TX100,TB100,TW100,TD100,TL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>C</term>
	///     <term>CX100,CB100,CW100,CD100,CL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>D</term>
	///     <term>DX100,DB100,DW100,DD100,DL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>S</term>
	///     <term>SX100,SB100,SW100,SD100,SL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>Q</term>
	///     <term>QX100,QB100,QW100,QD100,QL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>I</term>
	///     <term>IX100,IB100,IW100,ID100,IL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>N</term>
	///     <term>NX100,NB100,NW100,ND100,NL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>U</term>
	///     <term>UX100,UB100,UW100,UD100,UL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>Z</term>
	///     <term>ZX100,ZB100,ZW100,ZD100,ZL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>R</term>
	///     <term>RX100,RB100,RW100,RD100,RL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	/// </list>
	/// </remarks>
	// Token: 0x02000086 RID: 134
	public class XGKFastEnet : NetworkDeviceBase
	{
		/// <summary>
		/// Instantiate a Default object
		/// </summary>
		// Token: 0x06000A4F RID: 2639 RVA: 0x0003DB80 File Offset: 0x0003BD80
		public XGKFastEnet()
		{
			base.WordLength = 2;
			this.IpAddress = "127.0.0.1";
			this.Port = 2004;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <summary>
		/// Instantiate a object by ipaddress and port
		/// </summary>
		/// <param name="ipAddress">the ip address of the plc</param>
		/// <param name="port">the port of the plc, default is 2004</param>
		// Token: 0x06000A50 RID: 2640 RVA: 0x0003DBE4 File Offset: 0x0003BDE4
		public XGKFastEnet(string ipAddress, int port)
		{
			base.WordLength = 2;
			this.IpAddress = ipAddress;
			this.Port = port;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <summary>
		/// Instantiate a object by ipaddress, port, cpuType, slotNo
		/// </summary>
		/// <param name="CpuType">CpuType</param>
		/// <param name="ipAddress">the ip address of the plc</param>
		/// <param name="port">he port of the plc, default is 2004</param>
		/// <param name="slotNo">slot number</param>
		// Token: 0x06000A51 RID: 2641 RVA: 0x0003DC40 File Offset: 0x0003BE40
		public XGKFastEnet(string CpuType, string ipAddress, int port, byte slotNo)
		{
			this.SetCpuType = CpuType;
			base.WordLength = 2;
			this.IpAddress = ipAddress;
			this.Port = port;
			this.slotNo = slotNo;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <inheritdoc />
		// Token: 0x06000A52 RID: 2642 RVA: 0x0003BD9D File Offset: 0x00039F9D
		protected override INetMessage GetNewNetMessage()
		{
			return new LsisFastEnetMessage();
		}

		/// <summary>
		/// set plc
		/// </summary>
		// Token: 0x170001AE RID: 430
		// (get) Token: 0x06000A53 RID: 2643 RVA: 0x0003DCA9 File Offset: 0x0003BEA9
		// (set) Token: 0x06000A54 RID: 2644 RVA: 0x0003DCB1 File Offset: 0x0003BEB1
		public string SetCpuType { get; set; }

		/// <summary>
		/// CPU TYPE
		/// </summary>
		// Token: 0x170001AF RID: 431
		// (get) Token: 0x06000A55 RID: 2645 RVA: 0x0003DCBA File Offset: 0x0003BEBA
		// (set) Token: 0x06000A56 RID: 2646 RVA: 0x0003DCC2 File Offset: 0x0003BEC2
		public string CpuType { get; private set; }

		/// <summary>
		/// Cpu is error
		/// </summary>
		// Token: 0x170001B0 RID: 432
		// (get) Token: 0x06000A57 RID: 2647 RVA: 0x0003DCCB File Offset: 0x0003BECB
		// (set) Token: 0x06000A58 RID: 2648 RVA: 0x0003DCD3 File Offset: 0x0003BED3
		public bool CpuError { get; private set; }

		/// <summary>
		/// RUN, STOP, ERROR, DEBUG
		/// </summary>
		// Token: 0x170001B1 RID: 433
		// (get) Token: 0x06000A59 RID: 2649 RVA: 0x0003DCDC File Offset: 0x0003BEDC
		// (set) Token: 0x06000A5A RID: 2650 RVA: 0x0003DCE4 File Offset: 0x0003BEE4
		public LSCpuStatus LSCpuStatus { get; private set; }

		/// <summary>
		/// FEnet I/F module’s Base No.
		/// </summary>
		// Token: 0x170001B2 RID: 434
		// (get) Token: 0x06000A5B RID: 2651 RVA: 0x0003DCED File Offset: 0x0003BEED
		// (set) Token: 0x06000A5C RID: 2652 RVA: 0x0003DCF5 File Offset: 0x0003BEF5
		public byte BaseNo
		{
			get
			{
				return this.baseNo;
			}
			set
			{
				this.baseNo = value;
			}
		}

		/// <summary>
		/// FEnet I/F module’s Slot No.
		/// </summary>
		// Token: 0x170001B3 RID: 435
		// (get) Token: 0x06000A5D RID: 2653 RVA: 0x0003DCFE File Offset: 0x0003BEFE
		// (set) Token: 0x06000A5E RID: 2654 RVA: 0x0003DD06 File Offset: 0x0003BF06
		public byte SlotNo
		{
			get
			{
				return this.slotNo;
			}
			set
			{
				this.slotNo = value;
			}
		}

		/// <summary>
		///
		/// </summary>
		// Token: 0x170001B4 RID: 436
		// (get) Token: 0x06000A5F RID: 2655 RVA: 0x0003DD0F File Offset: 0x0003BF0F
		// (set) Token: 0x06000A60 RID: 2656 RVA: 0x0003DD17 File Offset: 0x0003BF17
		public LSCpuInfo CpuInfo
		{
			get
			{
				return this.cpuInfo;
			}
			set
			{
				this.cpuInfo = value;
			}
		}

		/// <summary>
		///
		/// </summary>
		// Token: 0x170001B5 RID: 437
		// (get) Token: 0x06000A61 RID: 2657 RVA: 0x0003DD20 File Offset: 0x0003BF20
		// (set) Token: 0x06000A62 RID: 2658 RVA: 0x0003DD28 File Offset: 0x0003BF28
		public string CompanyID
		{
			get
			{
				return this.CompanyID1;
			}
			set
			{
				this.CompanyID1 = value;
			}
		}

		/// <inheritdoc />
		// Token: 0x06000A63 RID: 2659 RVA: 0x0003DD34 File Offset: 0x0003BF34
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			XGKFastEnet.<ReadBoolAsync>d__36 <ReadBoolAsync>d__ = new XGKFastEnet.<ReadBoolAsync>d__36();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<XGKFastEnet.<ReadBoolAsync>d__36>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGKFastEnet.ReadCoil(System.String)" />
		// Token: 0x06000A64 RID: 2660 RVA: 0x0003DD88 File Offset: 0x0003BF88
		[DebuggerStepThrough]
		public Task<OperateResult<bool>> ReadCoilAsync(string address)
		{
			XGKFastEnet.<ReadCoilAsync>d__37 <ReadCoilAsync>d__ = new XGKFastEnet.<ReadCoilAsync>d__37();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<XGKFastEnet.<ReadCoilAsync>d__37>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGKFastEnet.ReadCoil(System.String,System.UInt16)" />
		// Token: 0x06000A65 RID: 2661 RVA: 0x0003DDD4 File Offset: 0x0003BFD4
		[DebuggerStepThrough]
		public Task<OperateResult<bool[]>> ReadCoilAsync(string address, ushort length)
		{
			XGKFastEnet.<ReadCoilAsync>d__38 <ReadCoilAsync>d__ = new XGKFastEnet.<ReadCoilAsync>d__38();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.length = length;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<XGKFastEnet.<ReadCoilAsync>d__38>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGKFastEnet.ReadByte(System.String)" />
		// Token: 0x06000A66 RID: 2662 RVA: 0x0003DE28 File Offset: 0x0003C028
		[DebuggerStepThrough]
		public Task<OperateResult<byte>> ReadByteAsync(string address)
		{
			XGKFastEnet.<ReadByteAsync>d__39 <ReadByteAsync>d__ = new XGKFastEnet.<ReadByteAsync>d__39();
			<ReadByteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte>>.Create();
			<ReadByteAsync>d__.<>4__this = this;
			<ReadByteAsync>d__.address = address;
			<ReadByteAsync>d__.<>1__state = -1;
			<ReadByteAsync>d__.<>t__builder.Start<XGKFastEnet.<ReadByteAsync>d__39>(ref <ReadByteAsync>d__);
			return <ReadByteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGKFastEnet.Write(System.String,System.Byte)" />
		// Token: 0x06000A67 RID: 2663 RVA: 0x0003DE74 File Offset: 0x0003C074
		[DebuggerStepThrough]
		public Task<OperateResult> WriteAsync(string address, byte value)
		{
			XGKFastEnet.<WriteAsync>d__40 <WriteAsync>d__ = new XGKFastEnet.<WriteAsync>d__40();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<XGKFastEnet.<WriteAsync>d__40>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGKFastEnet.WriteCoil(System.String,System.Boolean)" />
		// Token: 0x06000A68 RID: 2664 RVA: 0x0003DEC8 File Offset: 0x0003C0C8
		[DebuggerStepThrough]
		public Task<OperateResult> WriteCoilAsync(string address, bool value)
		{
			XGKFastEnet.<WriteCoilAsync>d__41 <WriteCoilAsync>d__ = new XGKFastEnet.<WriteCoilAsync>d__41();
			<WriteCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteCoilAsync>d__.<>4__this = this;
			<WriteCoilAsync>d__.address = address;
			<WriteCoilAsync>d__.value = value;
			<WriteCoilAsync>d__.<>1__state = -1;
			<WriteCoilAsync>d__.<>t__builder.Start<XGKFastEnet.<WriteCoilAsync>d__41>(ref <WriteCoilAsync>d__);
			return <WriteCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGKFastEnet.Write(System.String,System.Boolean)" />
		// Token: 0x06000A69 RID: 2665 RVA: 0x0003DF1C File Offset: 0x0003C11C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool value)
		{
			XGKFastEnet.<WriteAsync>d__42 <WriteAsync>d__ = new XGKFastEnet.<WriteAsync>d__42();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<XGKFastEnet.<WriteAsync>d__42>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000A6A RID: 2666 RVA: 0x0003DF70 File Offset: 0x0003C170
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			List<XGTAddressData> list = new List<XGTAddressData>();
			string[] array = address.Split(new string[]
			{
				";",
				","
			}, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text in array)
			{
				XGTAddressData xgtaddressData = new XGTAddressData();
				OperateResult<XGT_DataType, bool> dataTypeToAddress = XGKFastEnet.GetDataTypeToAddress(text);
				bool content = dataTypeToAddress.Content2;
				if (content)
				{
					xgtaddressData.Address = text.Substring(1);
				}
				else
				{
					xgtaddressData.Address = text.Substring(2);
				}
				list.Add(xgtaddressData);
			}
			OperateResult<XGT_MemoryType> operateResult = XGKFastEnet.AnalysisAddress(array[0]);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult<XGT_DataType, bool> dataTypeToAddress2 = XGKFastEnet.GetDataTypeToAddress(array[0]);
				bool flag2 = !dataTypeToAddress2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(dataTypeToAddress2);
				}
				else
				{
					bool flag3 = dataTypeToAddress2.Content1 == XGT_DataType.Continue;
					OperateResult<byte[]> operateResult2;
					if (flag3)
					{
						operateResult2 = this.Read(dataTypeToAddress2.Content1, list, operateResult.Content, 1, (int)length);
					}
					else
					{
						operateResult2 = this.Read(dataTypeToAddress2.Content1, list, operateResult.Content, 1, 0);
					}
					bool flag4 = !operateResult2.IsSuccess;
					if (flag4)
					{
						result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
					}
					else
					{
						OperateResult<byte[]> operateResult3 = base.ReadFromCoreServer(operateResult2.Content);
						bool flag5 = !operateResult3.IsSuccess;
						if (flag5)
						{
							result = OperateResult.CreateFailedResult<byte[]>(operateResult3);
						}
						else
						{
							bool flag6 = list.Count > 1;
							if (flag6)
							{
								result = this.ExtractActualDatabyte(operateResult3.Content);
							}
							else
							{
								result = this.ExtractActualData(operateResult3.Content);
							}
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000A6B RID: 2667 RVA: 0x0003E118 File Offset: 0x0003C318
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			List<XGTAddressData> list = new List<XGTAddressData>();
			string[] array = address.Split(new string[]
			{
				";",
				","
			}, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text in array)
			{
				XGTAddressData xgtaddressData = new XGTAddressData();
				OperateResult<XGT_DataType, bool> dataTypeToAddress = XGKFastEnet.GetDataTypeToAddress(text);
				bool content = dataTypeToAddress.Content2;
				if (content)
				{
					xgtaddressData.Address = text.Substring(1);
				}
				else
				{
					xgtaddressData.Address = text.Substring(2);
				}
				xgtaddressData.DataByteArray = value;
				list.Add(xgtaddressData);
			}
			OperateResult<XGT_MemoryType> operateResult = XGKFastEnet.AnalysisAddress(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult<XGT_DataType, bool> dataTypeToAddress2 = XGKFastEnet.GetDataTypeToAddress(address);
				bool flag2 = !dataTypeToAddress2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(dataTypeToAddress2);
				}
				else
				{
					bool flag3 = dataTypeToAddress2.Content1 == XGT_DataType.Continue;
					OperateResult<byte[]> operateResult2;
					if (flag3)
					{
						operateResult2 = this.Write(dataTypeToAddress2.Content1, list, operateResult.Content, 1, value.Length);
					}
					else
					{
						operateResult2 = this.Write(dataTypeToAddress2.Content1, list, operateResult.Content, 1, 0);
					}
					bool flag4 = !operateResult2.IsSuccess;
					if (flag4)
					{
						result = operateResult2;
					}
					else
					{
						OperateResult<byte[]> operateResult3 = base.ReadFromCoreServer(operateResult2.Content);
						bool flag5 = !operateResult3.IsSuccess;
						if (flag5)
						{
							result = OperateResult.CreateFailedResult<byte[]>(operateResult3);
						}
						else
						{
							result = this.ExtractActualData(operateResult3.Content);
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000A6C RID: 2668 RVA: 0x0003E2A0 File Offset: 0x0003C4A0
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			List<XGTAddressData> list = new List<XGTAddressData>();
			string[] array = address.Split(new string[]
			{
				";",
				","
			}, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text in array)
			{
				XGTAddressData xgtaddressData = new XGTAddressData();
				OperateResult<XGT_DataType, bool> dataTypeToAddress = XGKFastEnet.GetDataTypeToAddress(text);
				bool content = dataTypeToAddress.Content2;
				if (content)
				{
					xgtaddressData.Address = text.Substring(1);
				}
				else
				{
					xgtaddressData.Address = text.Substring(2);
				}
				list.Add(xgtaddressData);
			}
			OperateResult<XGT_MemoryType> operateResult = XGKFastEnet.AnalysisAddress(array[0]);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				OperateResult<XGT_DataType, bool> dataTypeToAddress2 = XGKFastEnet.GetDataTypeToAddress(array[0]);
				bool flag2 = !dataTypeToAddress2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool[]>(dataTypeToAddress2);
				}
				else
				{
					bool flag3 = dataTypeToAddress2.Content1 == XGT_DataType.Continue;
					OperateResult<byte[]> operateResult2;
					if (flag3)
					{
						operateResult2 = this.Read(dataTypeToAddress2.Content1, list, operateResult.Content, 1, (int)length);
					}
					else
					{
						operateResult2 = this.Read(dataTypeToAddress2.Content1, list, operateResult.Content, 1, 0);
					}
					bool flag4 = !operateResult2.IsSuccess;
					if (flag4)
					{
						result = OperateResult.CreateFailedResult<bool[]>(operateResult2);
					}
					else
					{
						OperateResult<byte[]> operateResult3 = base.ReadFromCoreServer(operateResult2.Content);
						bool flag5 = !operateResult3.IsSuccess;
						if (flag5)
						{
							result = OperateResult.CreateFailedResult<bool[]>(operateResult3);
						}
						else
						{
							bool flag6 = list.Count > 1;
							if (flag6)
							{
								OperateResult<bool[]> operateResult4 = this.ExtractActualDataBool(operateResult3.Content);
								bool flag7 = !operateResult4.IsSuccess;
								if (flag7)
								{
									result = OperateResult.CreateFailedResult<bool[]>(operateResult4);
								}
								else
								{
									result = OperateResult.CreateSuccessResult<bool[]>(operateResult4.Content);
								}
							}
							else
							{
								OperateResult<byte[]> operateResult5 = this.ExtractActualData(operateResult3.Content);
								bool flag8 = !operateResult5.IsSuccess;
								if (flag8)
								{
									result = OperateResult.CreateFailedResult<bool[]>(operateResult5);
								}
								else
								{
									result = OperateResult.CreateSuccessResult<bool[]>(SoftBasic.ByteToBoolArray(operateResult5.Content));
								}
							}
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// ReadCoil
		/// </summary>
		/// <param name="address">Start address</param>
		/// <returns>Whether to read the successful</returns>
		// Token: 0x06000A6D RID: 2669 RVA: 0x0003AED6 File Offset: 0x000390D6
		public OperateResult<bool> ReadCoil(string address)
		{
			return this.ReadBool(address);
		}

		/// <summary>
		/// ReadCoil
		/// </summary>
		/// <param name="address">Start address</param>
		/// <param name="length">read address length</param>
		/// <returns>Whether to read the successful</returns>
		// Token: 0x06000A6E RID: 2670 RVA: 0x0003AEDF File Offset: 0x000390DF
		public OperateResult<bool[]> ReadCoil(string address, ushort length)
		{
			return this.ReadBool(address, length);
		}

		/// <summary>
		/// Read single byte value from plc
		/// </summary>
		/// <param name="address">Start address</param>
		/// <returns>Whether to write the successful</returns>
		// Token: 0x06000A6F RID: 2671 RVA: 0x0001BA1E File Offset: 0x00019C1E
		[HslMqttApi("ReadByte", "")]
		public OperateResult<byte> ReadByte(string address)
		{
			return ByteTransformHelper.GetResultFromArray<byte>(this.Read(address, 1));
		}

		/// <summary>
		/// Write single byte value to plc
		/// </summary>
		/// <param name="address">Start address</param>
		/// <param name="value">value</param>
		/// <returns>Whether to write the successful</returns>
		// Token: 0x06000A70 RID: 2672 RVA: 0x0001BA2D File Offset: 0x00019C2D
		[HslMqttApi("WriteByte", "")]
		public OperateResult Write(string address, byte value)
		{
			return this.Write(address, new byte[]
			{
				value
			});
		}

		/// <summary>
		/// WriteCoil
		/// </summary>
		/// <param name="address">Start address</param>
		/// <param name="value">bool value</param>
		/// <returns>Whether to write the successful</returns>
		// Token: 0x06000A71 RID: 2673 RVA: 0x0003E4A4 File Offset: 0x0003C6A4
		public OperateResult WriteCoil(string address, bool value)
		{
			byte[] array = new byte[2];
			array[0] = (value ? 1 : 0);
			return this.Write(address, array);
		}

		/// <summary>
		/// WriteCoil
		/// </summary>
		/// <param name="address">Start address</param>
		/// <param name="value">bool value</param>
		/// <returns>Whether to write the successful</returns>
		// Token: 0x06000A72 RID: 2674 RVA: 0x0003E4CE File Offset: 0x0003C6CE
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			return this.WriteCoil(address, value);
		}

		/// <summary>
		/// Read
		/// </summary>
		/// <param name="pDataType"></param>
		/// <param name="pAddress"></param>
		/// <param name="pMemtype"></param>
		/// <param name="pInvokeID"></param>
		/// <param name="pDataCount"></param>
		/// <returns></returns>
		// Token: 0x06000A73 RID: 2675 RVA: 0x0003E4D8 File Offset: 0x0003C6D8
		public OperateResult<byte[]> Read(XGT_DataType pDataType, List<XGTAddressData> pAddress, XGT_MemoryType pMemtype, int pInvokeID, int pDataCount = 0)
		{
			bool flag = pAddress.Count > 16;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = new OperateResult<byte[]>("You cannot read more than 16 pieces.");
			}
			else
			{
				try
				{
					byte[] array = this.CreateReadDataFormat(XGT_Request_Func.Read, pDataType, pAddress, pMemtype, pDataCount);
					byte[] array2 = this.CreateHeader(pInvokeID, array.Length);
					byte[] value = new byte[array2.Length + array.Length];
					int num = 0;
					this.AddByte(array2, ref num, ref value);
					this.AddByte(array, ref num, ref value);
					result = OperateResult.CreateSuccessResult<byte[]>(value);
				}
				catch (Exception ex)
				{
					result = new OperateResult<byte[]>("ERROR:" + ex.Message.ToString());
				}
			}
			return result;
		}

		/// <summary>
		/// Write
		/// </summary>
		/// <param name="pDataType"></param>
		/// <param name="pAddressList"></param>
		/// <param name="pMemtype"></param>
		/// <param name="pInvokeID"></param>
		/// <param name="pDataCount"></param>
		/// <returns></returns>
		// Token: 0x06000A74 RID: 2676 RVA: 0x0003E584 File Offset: 0x0003C784
		public OperateResult<byte[]> Write(XGT_DataType pDataType, List<XGTAddressData> pAddressList, XGT_MemoryType pMemtype, int pInvokeID, int pDataCount = 0)
		{
			OperateResult<byte[]> result;
			try
			{
				byte[] array = this.CreateWriteDataFormat(XGT_Request_Func.Write, pDataType, pAddressList, pMemtype, pDataCount);
				byte[] array2 = this.CreateHeader(pInvokeID, array.Length);
				byte[] value = new byte[array2.Length + array.Length];
				int num = 0;
				this.AddByte(array2, ref num, ref value);
				this.AddByte(array, ref num, ref value);
				result = OperateResult.CreateSuccessResult<byte[]>(value);
			}
			catch (Exception ex)
			{
				result = new OperateResult<byte[]>("ERROR:" + ex.Message.ToString());
			}
			return result;
		}

		/// <summary>
		/// CreateHeader
		/// </summary>
		/// <param name="pInvokeID"></param>
		/// <param name="pDataByteLenth"></param>
		/// <returns></returns>
		// Token: 0x06000A75 RID: 2677 RVA: 0x0003E614 File Offset: 0x0003C814
		public byte[] CreateHeader(int pInvokeID, int pDataByteLenth)
		{
			byte[] bytes = Encoding.ASCII.GetBytes(this.CompanyID);
			byte[] bytes2 = BitConverter.GetBytes(0);
			byte[] bytes3 = BitConverter.GetBytes(0);
			byte[] array = new byte[1];
			switch (this.cpuInfo)
			{
			case LSCpuInfo.XGK:
				array[0] = 160;
				break;
			case LSCpuInfo.XGI:
				array[0] = 164;
				break;
			case LSCpuInfo.XGR:
				array[0] = 168;
				break;
			case LSCpuInfo.XGB_MK:
				array[0] = 176;
				break;
			case LSCpuInfo.XGB_IEC:
				array[0] = 180;
				break;
			}
			byte[] array2 = new byte[]
			{
				51
			};
			byte[] bytes4 = BitConverter.GetBytes((short)pInvokeID);
			byte[] bytes5 = BitConverter.GetBytes((short)pDataByteLenth);
			byte[] array3 = new byte[]
			{
				this.baseNo * 16 + this.slotNo
			};
			byte[] array4 = new byte[]
			{
				0
			};
			int num = bytes.Length + bytes2.Length + bytes3.Length + array.Length + array2.Length + bytes4.Length + bytes5.Length + array3.Length + array4.Length;
			byte[] result = new byte[num];
			int num2 = 0;
			this.AddByte(bytes, ref num2, ref result);
			this.AddByte(bytes2, ref num2, ref result);
			this.AddByte(bytes3, ref num2, ref result);
			this.AddByte(array, ref num2, ref result);
			this.AddByte(array2, ref num2, ref result);
			this.AddByte(bytes4, ref num2, ref result);
			this.AddByte(bytes5, ref num2, ref result);
			this.AddByte(array3, ref num2, ref result);
			this.AddByte(array4, ref num2, ref result);
			return result;
		}

		// Token: 0x06000A76 RID: 2678 RVA: 0x0003E7A0 File Offset: 0x0003C9A0
		private byte[] CreateReadDataFormat(XGT_Request_Func emFunc, XGT_DataType emDatatype, List<XGTAddressData> pAddressList, XGT_MemoryType emMemtype, int pDataCount)
		{
			List<XGTAddressData> list = new List<XGTAddressData>();
			int num = 0;
			byte[] bytes = BitConverter.GetBytes((short)emFunc);
			byte[] bytes2 = BitConverter.GetBytes((short)emDatatype);
			byte[] bytes3 = BitConverter.GetBytes(0);
			byte[] bytes4 = BitConverter.GetBytes((short)pAddressList.Count);
			num = bytes.Length + bytes2.Length + bytes3.Length + bytes4.Length;
			foreach (XGTAddressData xgtaddressData in pAddressList)
			{
				string addressString = this.CreateValueName(emDatatype, emMemtype, xgtaddressData.Address);
				XGTAddressData xgtaddressData2 = new XGTAddressData();
				xgtaddressData2.AddressString = addressString;
				list.Add(xgtaddressData2);
				num += xgtaddressData2.AddressByteArray.Length + xgtaddressData2.LengthByteArray.Length;
			}
			bool flag = XGT_DataType.Continue == emDatatype && XGT_Request_Func.Read == emFunc;
			if (flag)
			{
				num += 2;
			}
			byte[] result = new byte[num];
			int num2 = 0;
			this.AddByte(bytes, ref num2, ref result);
			this.AddByte(bytes2, ref num2, ref result);
			this.AddByte(bytes3, ref num2, ref result);
			this.AddByte(bytes4, ref num2, ref result);
			foreach (XGTAddressData xgtaddressData3 in list)
			{
				this.AddByte(xgtaddressData3.LengthByteArray, ref num2, ref result);
				this.AddByte(xgtaddressData3.AddressByteArray, ref num2, ref result);
			}
			bool flag2 = XGT_DataType.Continue == emDatatype;
			if (flag2)
			{
				byte[] bytes5 = BitConverter.GetBytes((short)pDataCount);
				this.AddByte(bytes5, ref num2, ref result);
			}
			return result;
		}

		// Token: 0x06000A77 RID: 2679 RVA: 0x0003E954 File Offset: 0x0003CB54
		private byte[] CreateWriteDataFormat(XGT_Request_Func emFunc, XGT_DataType emDatatype, List<XGTAddressData> pAddressList, XGT_MemoryType emMemtype, int pDataCount)
		{
			int num = 0;
			byte[] bytes = BitConverter.GetBytes((short)emFunc);
			byte[] bytes2 = BitConverter.GetBytes((short)emDatatype);
			byte[] bytes3 = BitConverter.GetBytes(0);
			byte[] bytes4 = BitConverter.GetBytes((short)pAddressList.Count);
			num = bytes.Length + bytes2.Length + bytes3.Length + bytes4.Length;
			List<XGTAddressData> list = new List<XGTAddressData>();
			foreach (XGTAddressData xgtaddressData in pAddressList)
			{
				string addressString = this.CreateValueName(emDatatype, emMemtype, xgtaddressData.Address);
				xgtaddressData.AddressString = addressString;
				int num2 = xgtaddressData.DataByteArray.Length;
				num += xgtaddressData.AddressByteArray.Length + xgtaddressData.LengthByteArray.Length + 2 + num2;
				list.Add(xgtaddressData);
			}
			bool flag = XGT_DataType.Continue == emDatatype && XGT_Request_Func.Read == emFunc;
			if (flag)
			{
				num += 2;
			}
			byte[] result = new byte[num];
			int num3 = 0;
			this.AddByte(bytes, ref num3, ref result);
			this.AddByte(bytes2, ref num3, ref result);
			this.AddByte(bytes3, ref num3, ref result);
			this.AddByte(bytes4, ref num3, ref result);
			foreach (XGTAddressData xgtaddressData2 in list)
			{
				this.AddByte(xgtaddressData2.LengthByteArray, ref num3, ref result);
				this.AddByte(xgtaddressData2.AddressByteArray, ref num3, ref result);
			}
			foreach (XGTAddressData xgtaddressData3 in list)
			{
				byte[] bytes5 = BitConverter.GetBytes((short)xgtaddressData3.DataByteArray.Length);
				this.AddByte(bytes5, ref num3, ref result);
				this.AddByte(xgtaddressData3.DataByteArray, ref num3, ref result);
			}
			return result;
		}

		/// <summary>
		///             Create a memory address variable name.
		/// </summary>
		/// <param name="dataType">데이터타입</param>
		/// <param name="memType">메모리타입</param>
		/// <param name="pAddress">주소번지</param>
		/// <returns></returns>
		// Token: 0x06000A78 RID: 2680 RVA: 0x0003EB5C File Offset: 0x0003CD5C
		public string CreateValueName(XGT_DataType dataType, XGT_MemoryType memType, string pAddress)
		{
			string empty = string.Empty;
			string memTypeChar = this.GetMemTypeChar(memType);
			string typeChar = this.GetTypeChar(dataType);
			bool flag = dataType == XGT_DataType.Continue;
			if (flag)
			{
				pAddress = (Convert.ToInt32(pAddress) * 2).ToString();
			}
			bool flag2 = dataType == XGT_DataType.Bit;
			if (flag2)
			{
				string value = pAddress.Substring(0, pAddress.Length - 1);
				string value2 = pAddress.Substring(pAddress.Length - 1);
				int num = Convert.ToInt32(value2, 16);
				pAddress = (Convert.ToInt32(value) * 16 + num).ToString();
			}
			return "%" + memTypeChar + typeChar + pAddress;
		}

		/// <summary>
		/// Char return according to data type
		/// </summary>
		/// <param name="type">데이터타입</param>
		/// <returns></returns>
		// Token: 0x06000A79 RID: 2681 RVA: 0x0003EC04 File Offset: 0x0003CE04
		private string GetTypeChar(XGT_DataType type)
		{
			string result = string.Empty;
			switch (type)
			{
			case XGT_DataType.Bit:
				result = "X";
				break;
			case XGT_DataType.Byte:
				result = "B";
				break;
			case XGT_DataType.Word:
				result = "W";
				break;
			case XGT_DataType.DWord:
				result = "D";
				break;
			case XGT_DataType.LWord:
				result = "L";
				break;
			default:
				if (type != XGT_DataType.Continue)
				{
					result = "X";
				}
				else
				{
					result = "B";
				}
				break;
			}
			return result;
		}

		/// <summary>
		/// Char return according to memory type
		/// </summary>
		/// <param name="type">메모리타입</param>
		/// <returns></returns>
		// Token: 0x06000A7A RID: 2682 RVA: 0x0003EC80 File Offset: 0x0003CE80
		private string GetMemTypeChar(XGT_MemoryType type)
		{
			string result = string.Empty;
			switch (type)
			{
			case XGT_MemoryType.IO:
				result = "P";
				break;
			case XGT_MemoryType.SubRelay:
				result = "M";
				break;
			case XGT_MemoryType.LinkRelay:
				result = "L";
				break;
			case XGT_MemoryType.KeepRelay:
				result = "K";
				break;
			case XGT_MemoryType.EtcRelay:
				result = "F";
				break;
			case XGT_MemoryType.Timer:
				result = "T";
				break;
			case XGT_MemoryType.Counter:
				result = "C";
				break;
			case XGT_MemoryType.DataRegister:
				result = "D";
				break;
			case XGT_MemoryType.ComDataRegister:
				result = "N";
				break;
			case XGT_MemoryType.FileDataRegister:
				result = "R";
				break;
			case XGT_MemoryType.StepRelay:
				result = "S";
				break;
			case XGT_MemoryType.SpecialRegister:
				result = "U";
				break;
			}
			return result;
		}

		/// <summary>
		/// 바이트 합치기
		/// </summary>
		/// <param name="item">개별바이트</param>
		/// <param name="idx">전체바이트에 개별바이트를 합칠 인덱스</param>
		/// <param name="header">전체바이트</param>
		/// <returns>전체 바이트 </returns>
		// Token: 0x06000A7B RID: 2683 RVA: 0x0003ED38 File Offset: 0x0003CF38
		private byte[] AddByte(byte[] item, ref int idx, ref byte[] header)
		{
			Array.Copy(item, 0, header, idx, item.Length);
			idx += item.Length;
			return header;
		}

		/// <summary>
		/// AnalysisAddress XGT_MemoryType
		/// </summary>
		/// <param name="address"></param>
		/// <returns></returns>
		// Token: 0x06000A7C RID: 2684 RVA: 0x0003ED64 File Offset: 0x0003CF64
		public static OperateResult<XGT_MemoryType> AnalysisAddress(string address)
		{
			XGT_MemoryType value = XGT_MemoryType.IO;
			try
			{
				char[] array = new char[]
				{
					'P',
					'M',
					'L',
					'K',
					'F',
					'T',
					'C',
					'D',
					'S',
					'Q',
					'I',
					'N',
					'U',
					'Z',
					'R'
				};
				bool flag = false;
				for (int i = 0; i < array.Length; i++)
				{
					bool flag2 = array[i] == address[0];
					if (flag2)
					{
						switch (address[0])
						{
						case 'C':
							value = XGT_MemoryType.Counter;
							break;
						case 'D':
							value = XGT_MemoryType.DataRegister;
							break;
						case 'F':
							value = XGT_MemoryType.EtcRelay;
							break;
						case 'K':
							value = XGT_MemoryType.KeepRelay;
							break;
						case 'L':
							value = XGT_MemoryType.LinkRelay;
							break;
						case 'M':
							value = XGT_MemoryType.SubRelay;
							break;
						case 'N':
							value = XGT_MemoryType.ComDataRegister;
							break;
						case 'P':
							value = XGT_MemoryType.IO;
							break;
						case 'R':
							value = XGT_MemoryType.FileDataRegister;
							break;
						case 'S':
							value = XGT_MemoryType.StepRelay;
							break;
						case 'T':
							value = XGT_MemoryType.Timer;
							break;
						case 'U':
							value = XGT_MemoryType.SpecialRegister;
							break;
						}
						flag = true;
						break;
					}
				}
				bool flag3 = !flag;
				if (flag3)
				{
					throw new Exception(StringResources.Language.NotSupportedDataType);
				}
			}
			catch (Exception ex)
			{
				return new OperateResult<XGT_MemoryType>(ex.Message);
			}
			return OperateResult.CreateSuccessResult<XGT_MemoryType>(value);
		}

		/// <summary>
		/// GetDataTypeToAddress
		/// </summary>
		/// <param name="address"></param>
		/// <returns></returns>
		// Token: 0x06000A7D RID: 2685 RVA: 0x0003EEB4 File Offset: 0x0003D0B4
		public static OperateResult<XGT_DataType, bool> GetDataTypeToAddress(string address)
		{
			XGT_DataType value = XGT_DataType.Bit;
			bool value2 = false;
			try
			{
				char[] array = new char[]
				{
					'P',
					'M',
					'L',
					'K',
					'F',
					'T',
					'C',
					'D',
					'S',
					'Q',
					'I',
					'N',
					'U',
					'Z',
					'R'
				};
				bool flag = false;
				for (int i = 0; i < array.Length; i++)
				{
					bool flag2 = array[i] == address[0];
					if (flag2)
					{
						char c = address[1];
						char c2 = c;
						if (c2 <= 'L')
						{
							switch (c2)
							{
							case 'B':
								value = XGT_DataType.Byte;
								goto IL_9B;
							case 'C':
								value = XGT_DataType.Continue;
								goto IL_9B;
							case 'D':
								value = XGT_DataType.DWord;
								goto IL_9B;
							default:
								if (c2 == 'L')
								{
									value = XGT_DataType.LWord;
									goto IL_9B;
								}
								break;
							}
						}
						else
						{
							if (c2 == 'W')
							{
								value = XGT_DataType.Word;
								goto IL_9B;
							}
							if (c2 == 'X')
							{
								value = XGT_DataType.Bit;
								goto IL_9B;
							}
						}
						value2 = true;
						value = XGT_DataType.Continue;
						IL_9B:
						flag = true;
						break;
					}
				}
				bool flag3 = !flag;
				if (flag3)
				{
					throw new Exception(StringResources.Language.NotSupportedDataType);
				}
			}
			catch (Exception ex)
			{
				return new OperateResult<XGT_DataType, bool>(ex.Message);
			}
			return OperateResult.CreateSuccessResult<XGT_DataType, bool>(value, value2);
		}

		/// <summary>
		/// Returns true data content, supports read and write returns
		/// </summary>
		/// <param name="response">response data</param>
		/// <returns>real data</returns>
		// Token: 0x06000A7E RID: 2686 RVA: 0x0003EFC4 File Offset: 0x0003D1C4
		public OperateResult<byte[]> ExtractActualData(byte[] response)
		{
			OperateResult<bool> cpuTypeToPLC = this.GetCpuTypeToPLC(response);
			bool flag = !cpuTypeToPLC.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = new OperateResult<byte[]>(cpuTypeToPLC.Message);
			}
			else
			{
				bool flag2 = response[20] == 89;
				if (flag2)
				{
					result = OperateResult.CreateSuccessResult<byte[]>(new byte[0]);
				}
				else
				{
					bool flag3 = response[20] == 85;
					if (flag3)
					{
						try
						{
							ushort num = BitConverter.ToUInt16(response, 30);
							byte[] array = new byte[(int)num];
							Array.Copy(response, 32, array, 0, (int)num);
							return OperateResult.CreateSuccessResult<byte[]>(array);
						}
						catch (Exception ex)
						{
							return new OperateResult<byte[]>(ex.Message);
						}
					}
					result = new OperateResult<byte[]>(StringResources.Language.NotSupportedFunction);
				}
			}
			return result;
		}

		/// <summary>
		/// SetCpuType
		/// </summary>
		/// <param name="response"></param>
		/// <returns></returns>
		// Token: 0x06000A7F RID: 2687 RVA: 0x0003F080 File Offset: 0x0003D280
		public OperateResult<bool> GetCpuTypeToPLC(byte[] response)
		{
			try
			{
				bool flag = response.Length < 20;
				if (flag)
				{
					return new OperateResult<bool>("Length is less than 20:" + SoftBasic.ByteToHexString(response));
				}
				ushort num = BitConverter.ToUInt16(response, 10);
				BitArray bitArray = new BitArray(BitConverter.GetBytes(num));
				int num2 = (int)(num % 32);
				switch (num % 32)
				{
				case 1:
					this.CpuType = "XGK/R-CPUH";
					break;
				case 2:
					this.CpuType = "XGK-CPUS";
					break;
				case 4:
					this.CpuType = "XGK-CPUE";
					break;
				case 5:
					this.CpuType = "XGK/R-CPUH";
					break;
				case 6:
					this.CpuType = "XGB/XBCU";
					break;
				}
				this.CpuError = bitArray[7];
				bool flag2 = bitArray[8];
				if (flag2)
				{
					this.LSCpuStatus = LSCpuStatus.RUN;
				}
				bool flag3 = bitArray[9];
				if (flag3)
				{
					this.LSCpuStatus = LSCpuStatus.STOP;
				}
				bool flag4 = bitArray[10];
				if (flag4)
				{
					this.LSCpuStatus = LSCpuStatus.ERROR;
				}
				bool flag5 = bitArray[11];
				if (flag5)
				{
					this.LSCpuStatus = LSCpuStatus.DEBUG;
				}
				bool flag6 = response.Length < 28;
				if (flag6)
				{
					return new OperateResult<bool>("Length is less than 28:" + SoftBasic.ByteToHexString(response));
				}
				ushort num3 = BitConverter.ToUInt16(response, 26);
				bool flag7 = num3 > 0;
				if (flag7)
				{
					return new OperateResult<bool>((int)response[28], "Error:" + XGKFastEnet.GetErrorDesciption(response[28]));
				}
			}
			catch (Exception ex)
			{
				return new OperateResult<bool>(ex.Message);
			}
			return OperateResult.CreateSuccessResult<bool>(true);
		}

		/// <summary>
		/// Returns true data content, supports read and write returns
		/// </summary>
		/// <param name="response">response data</param>
		/// <returns>real data</returns>
		// Token: 0x06000A80 RID: 2688 RVA: 0x0003F244 File Offset: 0x0003D444
		public OperateResult<bool[]> ExtractActualDataBool(byte[] response)
		{
			OperateResult<bool> cpuTypeToPLC = this.GetCpuTypeToPLC(response);
			bool flag = !cpuTypeToPLC.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = new OperateResult<bool[]>(cpuTypeToPLC.Message);
			}
			else
			{
				bool flag2 = response[20] == 89;
				if (flag2)
				{
					result = OperateResult.CreateSuccessResult<bool[]>(new bool[0]);
				}
				else
				{
					bool flag3 = response[20] == 85;
					if (flag3)
					{
						int num = 28;
						byte[] array = new byte[2];
						byte[] array2 = new byte[2];
						byte[] array3 = new byte[2];
						Array.Copy(response, num, array, 0, 2);
						int num2 = (int)BitConverter.ToInt16(array, 0);
						List<bool> list = new List<bool>();
						num += 2;
						try
						{
							for (int i = 0; i < num2; i++)
							{
								Array.Copy(response, num, array2, 0, 2);
								int num3 = (int)BitConverter.ToInt16(array2, 0);
								num += 2;
								array3 = new byte[num3];
								Array.Copy(response, num, array3, 0, num3);
								num += num3;
								list.Add(BitConverter.ToBoolean(array3, 0));
							}
							return OperateResult.CreateSuccessResult<bool[]>(list.ToArray());
						}
						catch (Exception ex)
						{
							return new OperateResult<bool[]>(ex.Message);
						}
					}
					result = new OperateResult<bool[]>(StringResources.Language.NotSupportedFunction);
				}
			}
			return result;
		}

		/// <summary>
		/// Returns true data content, supports read and write returns
		/// </summary>
		/// <param name="response">response data</param>
		/// <returns>real data</returns>
		// Token: 0x06000A81 RID: 2689 RVA: 0x0003F390 File Offset: 0x0003D590
		public OperateResult<byte[]> ExtractActualDatabyte(byte[] response)
		{
			OperateResult<bool> cpuTypeToPLC = this.GetCpuTypeToPLC(response);
			bool flag = !cpuTypeToPLC.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = new OperateResult<byte[]>(cpuTypeToPLC.Message);
			}
			else
			{
				bool flag2 = response[20] == 89;
				if (flag2)
				{
					result = OperateResult.CreateSuccessResult<byte[]>(new byte[0]);
				}
				else
				{
					bool flag3 = response[20] == 85;
					if (flag3)
					{
						int num = 28;
						byte[] array = new byte[2];
						byte[] array2 = new byte[2];
						byte[] array3 = new byte[2];
						Array.Copy(response, num, array, 0, 2);
						int num2 = (int)BitConverter.ToInt16(array, 0);
						List<byte> list = new List<byte>();
						num += 2;
						try
						{
							for (int i = 0; i < num2; i++)
							{
								Array.Copy(response, num, array2, 0, 2);
								int num3 = (int)BitConverter.ToInt16(array2, 0);
								num += 2;
								Array.Copy(response, num, array3, 0, num3);
								num += num3;
								list.AddRange(array3);
							}
							return OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
						}
						catch (Exception ex)
						{
							return new OperateResult<byte[]>(ex.Message);
						}
					}
					result = new OperateResult<byte[]>(StringResources.Language.NotSupportedFunction);
				}
			}
			return result;
		}

		/// <summary>
		/// get the description of the error code meanning
		/// </summary>
		/// <param name="code">code value</param>
		/// <returns>string information</returns>
		// Token: 0x06000A82 RID: 2690 RVA: 0x0003F4D0 File Offset: 0x0003D6D0
		public static string GetErrorDesciption(byte code)
		{
			if (code <= 34)
			{
				switch (code)
				{
				case 0:
					return "Normal";
				case 1:
					return "Physical layer error (TX, RX unavailable)";
				case 2:
					break;
				case 3:
					return "There is no identifier of Function Block to receive in communication channel";
				case 4:
					return "Mismatch of data type";
				case 5:
					return "Reset is received from partner station";
				case 6:
					return "Communication instruction of partner station is not ready status";
				case 7:
					return "Device status of remote station is not desirable status";
				case 8:
					return "Access to some target is not available";
				case 9:
					return "Can’ t deal with communication instruction of partner station by too many reception";
				case 10:
					return "Time Out error";
				case 11:
					return "Structure error";
				case 12:
					return "Abort";
				case 13:
					return "Reject(local/remote)";
				case 14:
					return "Communication channel establishment error (Connect/Disconnect)";
				case 15:
					return "High speed communication and connection service error";
				default:
					if (code == 33)
					{
						return "Can’t find variable identifier";
					}
					if (code == 34)
					{
						return "Address error";
					}
					break;
				}
			}
			else
			{
				if (code == 50)
				{
					return "Response error";
				}
				if (code == 113)
				{
					return "Object Access Unsupported";
				}
				if (code == 187)
				{
					return "Unknown error code (communication code of other company) is received";
				}
			}
			return "Unknown error";
		}

		/// <inheritdoc />
		// Token: 0x06000A83 RID: 2691 RVA: 0x0003F622 File Offset: 0x0003D822
		public override string ToString()
		{
			return string.Format("XGkFastEnet[{0}:{1}]", this.IpAddress, this.Port);
		}

		// Token: 0x040002F9 RID: 761
		private string CompanyID1 = "LSIS-XGT";

		// Token: 0x040002FA RID: 762
		private LSCpuInfo cpuInfo = LSCpuInfo.XGK;

		// Token: 0x040002FB RID: 763
		private byte baseNo = 0;

		// Token: 0x040002FC RID: 764
		private byte slotNo = 3;
	}
}
